<template>
	<view class="container">
		<!--  -->
		<u-navbar :title-bold='true' title='工作经历' :border-bottom='false'></u-navbar>

		<!-- <view class="card">
			<view class="e">工作职位</view>
			<view class="i">
				<input type="text" v-model="work.position" placeholder="输入工作职位">
			</view>
		</view>
		<u-line></u-line> -->
		<view class="card">
			<view class="e">单位名称</view>
			<view class="i">
				<input type="text" v-model="work.company" placeholder="输入单位名称">
			</view>
		</view>
		<u-line></u-line>
		<view class="card">
			<view class="e">开始时间</view>
			<view class="i" @click="st=true">
				<text>{{work.start_time?work.start_time:'请选择开始时间'}}</text>
				<u-icon name="arrow-right" color="#c0c4cc" size="20"></u-icon>
				<u-picker v-model="st" @confirm="startTime" mode="time" :params="params" :end-year='date'
					:default-time="work.start_time"></u-picker>
			</view>
		</view>
		<u-line></u-line>
		<view class="card">
			<view class="e">结束时间</view>
			<view class="i" @click="et=true">
				<text>{{work.end_time?work.end_time:'请选择结束时间'}}</text>
				<u-icon name="arrow-right" color="#c0c4cc" size="20"></u-icon>
				<u-picker v-model="et" @confirm="endTime" mode="time" :params="params" :end-year='date'
					:default-time="work.start_time"></u-picker>
			</view>
		</view>




		<view @click="save()" class="btn">保存</view>

	</view>
</template>

<script>
	import {
		workDetail,
		addWork
	} from '@/api/index.js'
	export default {
		data() {
			return {
				work: {},
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				st: false,
				et: false,
				date: ''
			}
		},
		onLoad(option) {
			if (option.id != 'undefined') {
				this.init(option.id)
			}
			let date = new Date()
			this.date = date.getFullYear()
		},
		methods: {
			init(id) {
				let that = this
				workDetail({
					'id': id
				}).then(res => {
					if (res.code = 1) {
						that.work = res.data.detail
					} else {
						uni.showToast({
							title: res.msg
						})
					}
				})
			},
			startTime(e) {
				this.work.start_time = e.year + '-' + e.month
			},
			endTime(e) {
				this.work.end_time = e.year + '-' + e.month
			},
			save() {
				let that = this
				that.work.position = '护航员'
				addWork(that.work).then(res => {
					if (res.code == 1) {
						uni.navigateBack({
							delta: 1
						})
					} else {
						uni.showToast({
							title: res.msg
						})
					}
				})
			},

			editWork(item) {
				if (item == null) {
					console.log('ssssssss');
				} else {
					console.log(item);
				}
			}
		}
	}
</script>

<style lang="less">
	.container {
		background-color: #EEE;
		padding-bottom: 40px;
		font-size: 14px;
		color: black;

		.editfile {
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #6EC9E1;
			padding: 40rpx;
			color: #FFF;
			letter-spacing: 2px;
		}


		.card {
			padding: 40rpx;
			background-color: #FFF;
			display: flex;
			align-items: center;

			.e {
				margin-right: 20rpx;
				width: 30vw;
			}

			.i {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				text-align: end;
				flex: 2;

				text {
					opacity: 0.5;
				}

			}
		}

	}
</style>